import Router from 'vue-router';
import home from '../components/home'; // 我的
import shopping from '../components/shopping'; // 商城
import appFooter from '../pages/appFooter'; // 我的、商城。。。
import loginReg from '../pages/loginReg'; // 登录、注册
import notFound from '../pages/notFound'; // 404
import addRess from '../pages/addRess'; // 收获地址
import cart from '../pages/cart'; // 商品详情
import commodity from '../pages/commodity' // 购物车
import Confirmation from '../pages/Confirmation'; // 确认订单
import Limitedtime from '../pages/Limitedtime'; // 限时秒杀
import HotSearch from '../pages/HotSearch';  // 历史记录
import SearchRecord from '../pages/SearchRecord'; // 搜索记录
import payment from '../pages/payment'; // 支付

import classification from '../shopping/classification'; // 推荐
import BeautyMakeup from '../shopping/BeautyMakeup';   // 美妆护肤
import goods from '../shopping/goods'; // 百货
import WristWatch from '../shopping/WristWatch'; // 腕表
import household from '../shopping/household'; // 家电
import Luggage from '../shopping/Luggage'; // 箱包
import parts from '../shopping/parts'; // 配件
import Jewellery from '../shopping/Jewellery'; // 珠宝
import phone from '../shopping/phone'; // 手机

import Beauty from '../components/Beauty'; // 美妆综合
import apparatus from '../shopping/shopping--BeautyMakeup/apparatus'; // 口红
import BeautyMakeupTop from '../shopping/shopping--BeautyMakeup/BeautyMakeupTop'; // 美妆top20
import Cleansing from '../shopping/shopping--BeautyMakeup/Cleansing'; // 面膜
import Cosmetics from '../shopping/shopping--BeautyMakeup/Cosmetics'; // 护肤仪
import FacialMask from '../shopping/shopping--BeautyMakeup/FacialMask'; // 彩妆
import Lipstick from '../shopping/shopping--BeautyMakeup/Lipstick'; // 香水
import Perfume from '../shopping/shopping--BeautyMakeup/Perfume'; // 香水
import Replenishment from '../shopping/shopping--BeautyMakeup/Replenishment'; // 补水

import Choice from '../components/Choice'; // 底部组件
import addAddRess from  '../pages/addAddRess'; // 添加收货地址
import reviseAddRess from '../pages/revise-addRess' // 修改收货地址
import login from '../components/login'; // 登录
import register from '../components/register'; // 注册
const routes = [
  { path: '/', redirect: '/auth' }, // 重定向
  { path: '/auth',
    component: appFooter,
    redirect: '/auth/home', // 我的
    children: [
      { path: 'home', component: home, name: 'home'},
      { path: 'shopping', // 商城
        redirect: 'shopping/classification',
        component: Choice,
        children: [
          { path: 'classification', component: classification, name: 'classification'},
          { path: 'BeautyMakeup', // 美妆护肤
            redirect: 'BeautyMakeup/BeautyMakeupTop',
            component: Beauty,
            name:'BeautyMakeup',
            children: [
              { path: 'BeautyMakeupTop', component: BeautyMakeupTop, name: 'BeautyMakeupTop'},
              { path: 'apparatus', component: apparatus, name: 'apparatus'},
              { path: 'Cleansing', component: Cleansing, name: 'Cleansing'},
              { path: 'Cosmetics', component: Cosmetics, name: 'Cosmetics'},
              { path: 'FacialMask', component: FacialMask, name: 'FacialMask'},
              { path: 'Lipstick', component: Lipstick, name: 'Lipstick'},
              { path: 'Perfume', component: Perfume, name: 'Perfume'},
              { path: 'Replenishment', component: Replenishment, name: 'Replenishment'},
            ]
          },
          { path: 'goods', component: goods, name: 'goods'},
          { path: 'WristWatch', component: WristWatch, name: 'WristWatch'},
          { path: 'household', component: household, name: 'household'},
          { path: 'Luggage', component: Luggage, name: 'Luggage'},
          { path: 'parts', component: parts, name: 'parts'},
          { path: 'Jewellery', component: Jewellery, name: 'Jewellery'},
          { path: 'phone', component: phone, name: 'phone'},
        ]
      },
    ]
  },
  {path: '/auth',
    component: loginReg,
    redirect: '/auth/login',
    children: [
      {path: 'login', component: login},
      { path: 'register', component: register },
    ]
  }, //路由记录
  { path: '*', component: notFound },
  { path: '/auth/addRess',
    meta: {
    requireAuth:true,
    }, // 元数据
    component: addRess,
    name:'addRess'
  },
  { path: '/auth/addAddRess',
    meta: {
      requireAuth:true,
    },
    component: addAddRess,
    name:'addAddRess'
  },
  {
    path: '/auth/reviseAddRess',
    component: reviseAddRess,
    name: 'reviseAddRess',
  },
  {
    path: '/auth/cart',
    component: cart,
    name: 'cart',
  },
  {
    path: '/auth/commodity',
    component: commodity,
    name: 'commodity',
  },
  {
    path: '/auth/Confirmation',
    component: Confirmation,
    name: 'Confirmation',
  },
  {
    path: '/auth/Limitedtime',
    component: Limitedtime,
    name: 'Limitedtime',
  },
  {
    path: '/auth/HotSearch',
    component: HotSearch,
    name: 'HotSearch',
  },
  {
    path: '/auth/SearchRecord',
    component: SearchRecord,
    name: 'SearchRecord',
  },
  {
    path: '/auth/payment',
    component: payment,
    name: 'payment',
  },
  {
    path: '/auth/home',
    component: home,
    name: 'home',
  }
];
export const router = new Router({ // routes 缩写
  routes
});

var isLogin = false;

// beforeEach 全局守卫 路由跳转
router.beforeEach(function (to, from, next) {
  if(true){//表示登陆状态
    if(to.path =='/login'){
      next("/")
    }else{
      next()
    }
  }else{
    if(to.path!='/login'&& to.meta.requiresAuth){
      next({path:'/login'})
    }else{
      next()//放行了,不能少，否则不会执行跳转
    }
  }
});
